package demo1218.pm;

import java.util.Objects;

public class Student implements Comparable<Student>{
    private Integer stuId;
    private String name;

    public Student(Integer stuId, String name) {
        this.stuId = stuId;
        this.name = name;
    }

    public Student() {
    }

    public Integer getStuId() {
        return stuId;
    }

    public void setStuId(Integer stuId) {
        this.stuId = stuId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(stuId, student.stuId) &&
                Objects.equals(name, student.name);
    }

    /*
     * 比较此对象与指定对象的顺序。
     * 如果该对象小于、等于或大于指定对象，则分别返回负整数、零或正整数。
     * 1.如果此对象小于指定对象,返回负整数.
     * 2.如果此对象大于指定对象,返回正整数.
     * 3.如果此对象等于指定对象,返回0.
     * @param o
     * @return
     * 按照学号进行从小到大排序
     */
    @Override
    public int compareTo(Student o) {
        if(this.stuId>o.stuId){
            return -1;
        }else if (this.stuId<o.stuId){
            return 1;
        }else {
            return 0 ;
        }

    }

    @Override
    public String toString() {
        return "Student{" +
                "stuId=" + stuId +
                ", name='" + name + '\'' +
                '}';
    }
}
